import DS from 'ember-data';
import BaseModel from './base-model';
import Ember from 'ember';

export default BaseModel.extend({
  dateService: Ember.inject.service("date-service"),
  createDateTime:DS.attr('number'),// 数据创建时间
  deviceId: DS.attr('string'),// 按键ID 与老人按键绑定
  lastUpdateDateTime:DS.attr('number'),// 更新时间
  bed:DS.belongsTo('bed'),//床位
  createDate:DS.attr('number'),// 统计日期
  deepSleepMins:DS.attr('number'),// 深睡眠时间
  lightSleepMins:DS.attr('number'),// 浅睡眠时间
  allSleepMins:DS.attr('number'),// 总睡眠时间
  wakeUpMins:DS.attr('number'),// 醒着的时间
  customer:DS.belongsTo('customer'),//用户
  // remark: DS.attr('string'),//备注
  createDateStr:Ember.computed("createDate", function() {
      var createDate = this.get("createDate");
      return createDate?this.get("dateService").formatDate(createDate, "yyyy-MM-dd"):'无';
  }),
  deepSleepMinsFormat:Ember.computed("deepSleepMins", function() {
      let deepSleepMins = this.get("deepSleepMins");
      if(deepSleepMins == "0"){
        return '0分钟';
      }else{
        let hour = parseInt(deepSleepMins/60);
        let minute = deepSleepMins - (hour * 60);
        let str = "";
        if(hour){
          str += hour + "小时";
        }
        if(minute){
          str += minute + "分钟";
        }
        return str;
      }
  }),
  lightSleepMinsFormat:Ember.computed("lightSleepMins", function() {
      let lightSleepMins = this.get("lightSleepMins");
      if(lightSleepMins == "0"){
        return '0分钟';
      }else{
        let hour = parseInt(lightSleepMins/60);
        let minute = lightSleepMins - (hour * 60);
        let str = "";
        if(hour){
          str += hour + "小时";
        }
        if(minute){
          str += minute + "分钟";
        }
        return str;
      }
  }),
  allSleepMinsFormat:Ember.computed("allSleepMins", function() {
      let allSleepMins = this.get("allSleepMins");
      console.log("allSleepMins:",allSleepMins);
      if(allSleepMins == "0"){
        return '0分钟';
      }else{
        let hour = parseInt(allSleepMins/60);
        let minute = allSleepMins - (hour * 60);
        let str = "";
        console.log("allSleepMins hour:",hour);
        if(hour){
          str += hour + "小时";
        }
        console.log("allSleepMins minute:",minute);
        if(minute){
          str += minute + "分钟";
        }
        console.log("allSleepMins str:",str);
        return str;
      }
  }),
  deepSleepMinsFormatMin:Ember.computed("deepSleepMins", function() {
      let deepSleepMins = this.get("deepSleepMins");
      if(deepSleepMins == "0"){
        return '0分';
      }else{
        let hour = parseInt(deepSleepMins/60);
        let minute = deepSleepMins - (hour * 60);
        let str = "";
        if(hour){
          str += hour + "时";
        }
        if(minute){
          str += minute + "分";
        }
        return str;
      }
  }),
  lightSleepMinsFormatMin:Ember.computed("lightSleepMins", function() {
      let lightSleepMins = this.get("lightSleepMins");
      if(lightSleepMins == "0"){
        return '0分';
      }else{
        let hour = parseInt(lightSleepMins/60);
        let minute = lightSleepMins - (hour * 60);
        let str = "";
        if(hour){
          str += hour + "时";
        }
        if(minute){
          str += minute + "分";
        }
        return str;
      }
  }),
  allSleepMinsFormatMin:Ember.computed("allSleepMins", function() {
      let allSleepMins = this.get("allSleepMins");
      console.log("allSleepMins:",allSleepMins);
      if(allSleepMins == "0"){
        return '0分';
      }else{
        let hour = parseInt(allSleepMins/60);
        let minute = allSleepMins - (hour * 60);
        let str = "";
        console.log("allSleepMins hour:",hour);
        if(hour){
          str += hour + "时";
        }
        console.log("allSleepMins minute:",minute);
        if(minute){
          str += minute + "分";
        }
        console.log("allSleepMins str:",str);
        return str;
      }
  }),
});
